package com.cskaoyan.controller.admin.promotecontroller;


import com.cskaoyan.bean.promotebean.Topic;
import com.cskaoyan.service.promoteservice.TopicService;
import com.cskaoyan.vo.BaseRespVo;

import com.cskaoyan.vo.promotevo.TopicCreateVO;
import com.cskaoyan.vo.promotevo.TopicListVO;
import com.cskaoyan.vo.promotevo.TopicUpdateVO;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @Author: feisl
 * @Date: 2021/5/10 1:19
 */
@RestController
@RequestMapping("admin/topic")
public class TopicController {
    @Autowired
    TopicService topicService;

    @RequiresPermissions("admin:topic:list")
    @RequestMapping("list")
    public BaseRespVo list(Integer page, Integer limit, String title,String subtitle,String sort, String order)
    {
        TopicListVO topicListVO = topicService.queryTopicAll(page,limit,title,subtitle,sort,order);

        return BaseRespVo.ok(topicListVO);

    }
    @RequiresPermissions("admin:topic:create")
    @RequestMapping("create")
    public BaseRespVo create(@RequestBody Topic topic){

        TopicCreateVO topicCreateVO = topicService.insert(topic);

        return BaseRespVo.ok(topicCreateVO);
    }
    @RequiresPermissions("admin:topic:update")
    @RequestMapping("update")
    public BaseRespVo update(@RequestBody Topic topic){

        TopicUpdateVO topicUpdateVO = topicService.update(topic);

        return BaseRespVo.ok(topicUpdateVO,"成功");
    }

    @RequiresPermissions("admin:topic:delete")
    @RequestMapping("delete")
    public BaseRespVo delete(@RequestBody Map map){

        Object id = map.get("id");

        topicService.delete((Integer) id);

        return BaseRespVo.ok();
    }
}
